<template>
<div class="commentItem">
    <div class="top">
        <div class="left">
            <span>{{obj.user.nickname}}</span> &nbsp;&nbsp;&nbsp;
            <span>2分钟前</span>
        </div>
        <span @click="replyFn(obj.id)">回复</span>
    </div>
    <!-- 嵌套评论 star -->
      <!-- <div class="commentItem" v-if="obj.parent">
        <div class="top">
            <div class="left">
                <span>{{obj.parent.user.nickname}}</span> &nbsp;&nbsp;&nbsp;
                <span>2分钟前</span>
            </div>
            <span>回复</span>
        </div>
        <div class="bottom">{{obj.parent.content}}</div>
    </div> -->
    <!-- 递归组件 -->
    <commentItem @reply="replyFn" v-if="obj.parent" :obj="obj.parent"></commentItem>
    <!-- 嵌套评论 end -->
    <div class="bottom">{{obj.content}}</div>
</div>
</template>

<script>
export default {
  name: "commentItem", // 表示注册了commentItem组件（注册了自己这个组件）
    props: {
        obj: {
            type: Object,
            required: true
        }
    },
    methods: {
      replyFn(id){
        console.log(id);
        this.$emit("reply", id)
      }
    }
}
</script>

<style lang="less" scoped>
.commentItem {
  border: 1px solid #ccc;
  padding: 5px;
  margin-top: 10px;
  .top {
    font-size: 12px;
    color: #aaa;
    display: flex;
    justify-content: space-between;
  }
  .bottom {
    font-size: 13px;
    line-height: 40px;
  }
}
</style>